<?php

/*
 * 套系明细，套系与产品的关联表
 */

/**
 * Description of series_product_model
 *
 * @author Jack.Y
 */
class Series_Product_Model extends CI_Model {

    //重载CI_Model
    public function __construct() {
        parent::__construct();
        $this->load->database();
        $this->load->model('Base_Model');
    }

    /*
     * Insert_Product_Series
     * 写入数据库
     */

    function Insert_Product_Series($array = FALSE, $se_id = FALSE) {
        $sp_id = '';
        foreach ($array as $array_item) {
            $se_item = split(",", $array_item);
            $sp_id = $this->Base_Model->GetID('sp_id', 'db_series_product'); //获取标准ID
            $data = array(
                'sp_id' => $sp_id,
                'se_id' => $se_id,
                'pt_id' => $se_item[0],
                'pt_num' => $se_item[2],
                'sp_state' => OBJ_STATE_VALID
            );
            $this->db->insert('db_series_product', $data);
        }
    }

    /*
     * GetForState
     * 获取列表数据
     * 参数：状态;套系标示
     */

    function GetListForState($str = FALSE, $se_id = FALSE) {
        $this->db->select("db_series_product.pt_id,db_product.pt_name,db_series_product.pt_num,db_series.se_moeny");
        $this->db->from('db_series_product');
        $this->db->join('db_product', 'db_series_product.pt_id = db_product.pt_id');
        $this->db->join('db_series', 'db_series.se_id = db_series_product.se_id');
        $this->db->where('db_series.se_state', $str);
        $this->db->where('db_series_product.sp_state', $str);
        $this->db->where('db_series_product.se_id', $se_id);
        $query = $this->db->get();
        //返回结果
        return $query->result_array();
    }

    /*
     * DelDate
     * 删除数据
     */

    function DelDate($id = FALSE) {
        $this->db->delete('db_series_product', array('se_id' => $id));
    }

}

?>
